package hu.kisprof.quiz.controller;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class QuizServerConnectionListener extends  Thread {
	private QuizController controller;
	private ServerSocket ss;
	public QuizServerConnectionListener(QuizController controller){
		this.controller = controller;
	}
	
	public int getPort(){
		return ss.getLocalPort();
	}
	
	public void run() {
		try {
			ss = new ServerSocket(0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		while (true){
			Socket incoming = null;
			
			try {
				incoming = ss.accept();

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				continue;
			}
			new QuizIncomingServerConnection(incoming,controller).start();
		}
	}

	
	
	

}
